package com.ml.doctor.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ml.doctor.R;
import com.ml.doctor.bean.MyServiceBean;
import com.ml.doctor.view.FlowLayout;
import com.qiniu.android.utils.Collection2Utils;

import java.util.ArrayList;

public class MyServiceRecyclerAdapter extends RecyclerView.Adapter<MyServiceRecyclerAdapter.MyServiceHolder> {

    private LayoutInflater mInflater;
    private ArrayList<MyServiceBean> mDataList;
    private Context mContext;

    public MyServiceRecyclerAdapter(Context context, ArrayList<MyServiceBean> dataList){
        mInflater = LayoutInflater.from(context);
        mDataList = dataList;
        mContext = context;
    }

    @Override
    public MyServiceHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyServiceHolder(mInflater.inflate(R.layout.item_my_service, null));
    }

    @Override
    public void onBindViewHolder(MyServiceHolder holder, int position) {
        MyServiceBean itemBean = mDataList.get(position);
        holder.mNameTv.setText(itemBean.u.bname);
        Glide.with(mContext).load(itemBean.u.user_photo).asBitmap().into(holder.mAvatarIv);
        holder.mGoldTv.setText(String.valueOf(itemBean.dba));
        holder.mRb.setRating((float)itemBean.score / 100);
        holder.mContentTv.setContent(Collection2Utils.toArrayList(itemBean.content, ","));
        holder.mTimeTv.setText(itemBean.time);
    }

    @Override
    public int getItemCount() {
        return mDataList == null ? 0 : mDataList.size();
    }

    public class MyServiceHolder extends RecyclerView.ViewHolder {
        public TextView mNameTv;
        public ImageView mAvatarIv;
        public TextView mGoldTv;
        public RatingBar mRb;
        public FlowLayout mContentTv;
        public TextView mTimeTv;

        public MyServiceHolder(View view){
            super(view);
            mNameTv = (TextView) view.findViewById(R.id.tv_name);
            mAvatarIv = (ImageView) view.findViewById(R.id.iv_avatar);
            mGoldTv = (TextView) view.findViewById(R.id.tv_gold);
            mRb = (RatingBar) view.findViewById(R.id.rb_score);
            mContentTv = (FlowLayout) view.findViewById(R.id.flowlayout);
            mTimeTv = (TextView) view.findViewById(R.id.tv_time);
        }
    }
}
